<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<script src="updateDB.js"></script>
<script src="js/utils.js"></script>
<title>Open Badges - Upload Single Badge </title> 
</head>
<body>
<h1>Open Badges - Upload Single Badge</h1>

	<?php
		include "php/config.php"; 
		session_start();
		$num=(int)$_GET["num"];
		$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DB_NAME);
		 if ($mysqli->connect_errno) {
		echo "Failed to connect to MySQL: " . $mysqli->connect_error;
		}
		
		$query="SELECT bakedBadge from baked_badge WHERE verifyUrl='". $_SESSION['vettoreUrl'][$num] ."'";
		$result = $mysqli->query($query) or die('Query failed: ' . $mysqli->error);
		$row=$result->fetch_assoc();
		$badge_id=$row["bakedBadge"];
		
		// Free result set
		$result->close();
		
		// Closing connection
		$mysqli->close();
		
		echo '<script src="http://localhost:8888/issuer.js"></script>';
		echo "<a href=\"javascript:OpenBadges.issue(['" .$_SESSION['vettoreUrl'][$num] ."'],function(errors, successes){if(errors.length > 0) onIssue(". $_SESSION['id_utente'] ."," . $badge_id .",errors[0].reason); else success(". $_SESSION['id_utente'] ."," . $badge_id .");});\"> Claim your badge.</a>";
		
	?>
<div id="message"></div> 
<p>Torna alla mia <a href="earner.php">Pagina Personale</a></p>
</body>
</html>